<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Website_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
	
	function aa(){return 1123;}
	
	function insert_website($data){
	
		$str = $this->db->insert_string('sdk_site', $data);		
		$this->db->query($str);
		
		$id = $this->db->insert_id();
		//同时添加网站的汇率
		$str = $this->db->insert_string('sdk_currency', array('siteid'=>$data->siteid, 'set_currency'=>'a:3:{i:0;a:4:{s:8:"currency";s:3:"USD";s:6:"symbol";s:1:"$";s:9:"default_c";s:1:"1";s:4:"rate";s:1:"1";}i:1;a:4:{s:8:"currency";s:3:"GBP";s:6:"symbol";s:2:"£";s:9:"default_c";s:1:"1";s:4:"rate";s:1:"1";}i:2;a:4:{s:8:"currency";s:3:"EUR";s:6:"symbol";s:3:"€";s:9:"default_c";s:1:"1";s:4:"rate";s:1:"1";}}'));
		$this->db->query($str);
		
		return $id;
	}
	
	function websitenumrows(){

		$q = $this->db->query("select * from sdk_site");
		
		return $q->num_rows();

	}
	
	function searchtable($tablename='',$limit = '',$size = ''){
		
		$sql = "select * from $tablename limit ".$limit*$size.",".$size;
		$q = $this->db->query($sql);
		return $q->result();
	}
	
	function is_exist($siteid){
		$sql = "SELECT sitencrypt FROM sdk_site WHERE siteid = ? ";
		$q = $this->db->query($sql, $siteid);
		
		return $q->num_rows() > 0 ? true : false;
	}
	
	function getencrypt($siteid){
		$sql = "SELECT sitencrypt FROM sdk_site WHERE siteid = '" . $siteid . "' ";
		$q = $this->db->query($sql);
		$rs = $q->first_row(); 
		
		return $rs->sitencrypt;
	}
	
	function get_site_row($siteid){
		$sql = "select * from sdk_site where siteid='" . $siteid .  "'";
		
		$q = $this->db->query($sql);
		return $q->first_row();
	}
	
	function get_site_info($par = ''){
		$sql = "select * from sdk_site where ".$par;
		$q = $this->db->query($sql);
		return $q->row();	
	}
}